module chess {
	export class Zobrist {

		public hum: Array<any>;
		public com: Array<any>;
		public code: any;
		public size: number;

		public constructor(size) {
			this.size = size || 15;
		}

		public init() {
			this.com = [];
			this.hum = [];
			for (var i = 0; i < this.size * this.size; i++) {
				this.com.push(this.rand());
				this.hum.push(this.rand());
			}

			this.code = this.rand();
		}

		public go(x, y, role) {
			var index = this.size * x + y;
			this.code ^= (role == chess.ChessConst.role.com ? this.com[index] : this.hum[index]);
			return this.code;
		}

		public rand() {
			return Math.random() * 1000000000;
		}
	}
}